<?php

/**
 * @author Martin Pernica
 * @copyright 2008
 */

 echo '<br /><h2><a href="index.php?p=components&name=categories">'.Lang::getBackGlobal('back').'</a></h2><br />';
 if(!empty($_POST['name'])){
    
    $name = Registry::get('db')->real_escape_string( $_POST['name'] );
    $description = Registry::get('db')->real_escape_string( $_POST['description'] );
    
    $query = Registry::get('db')->query("INSERT INTO {prefix}categories (name, description, section) VALUES('".$name."', '".$description."', '".intval($_POST['section'])."')");
    $log->write(8, 'com_categories', 'NOW()', 'User created new category', $_SESSION['id']);
	
    messageBox( Lang::getBack('com_categories', 'category_added') );
    
 }

$sections = $db->query("SELECT id, name FROM {prefix}sections ORDER BY id DESC");
$select = array();

while($d = $sections->fetch_array()){
	$select[ $d['name'] ] = $d['id'];
}

$form = new Form;
$form->addTextbox('name', Lang::getBack('com_categories', 'name') );
$form->addTextbox('description', Lang::getBack('com_categories', 'description') );
$form->addElement('select', array('name' => 'section', 'label' => Lang::getBack('com_categories', 'section')), $select);
$form->addSubmit('submit', Lang::getBackGlobal('submit'));

echo $form;

?>